package cpr.data;

import java.util.Iterator;

import cpr.MainConst;
import cpr.Rule;
import cpr.Utils;
import cpr.context.ARComputeContext;

public class AREntry {
	public HLVector vector;
    public Rule rule;

    public String toString() {
    	//Utils.printRuleAccordingToVectorDigital(rule, vector)
        return "["+vector.score+"]"+" "+" "+rule.attrValue +" +?"+/*plus.size()*/ " -?" /*minus.size()*/;
    }
    public long[] binPlus;
    public long[] binMinus;
    
    public void computeBinaryPlusMinus(int num_records, ARComputeContext ctx) {
    	int longs = num_records / MainConst.EVAL_BIT_LENGTH;
    	if (longs*MainConst.EVAL_BIT_LENGTH<num_records) {
    		longs++;
    	}
    	binPlus = new long[longs];
    	binMinus = new long[longs];
    	int[] c_plus = new int[num_records];
    	int[] c_minus = new int[num_records];
    	for (Iterator iter = ctx._plus.iterator(); iter.hasNext();) {
			Rule aRule = (Rule)iter.next();
			int ci = aRule.ruleNr;
			c_plus[ci] = 1;
		}
    	for (Iterator iter = ctx._minus.iterator(); iter.hasNext();) {
			Rule aRule = (Rule)iter.next();
			int ci = aRule.ruleNr;
			c_minus[ci] = 1;
		}        	
    	int currLongIndex = 0;
    	int currBitIndex = 0;
		long a_plus_long = 0;
		long a_minus_long = 0;
    	for (int i = 0; i < c_plus.length; i++) {
    		if (currBitIndex==MainConst.EVAL_BIT_LENGTH) {
    			binPlus[currLongIndex] = a_plus_long;
    			binMinus[currLongIndex] = a_minus_long;
    			currLongIndex++;
    			currBitIndex=0;
    			a_plus_long = 0;
    			a_minus_long = 0;
    		}
    		int a_plus = c_plus[i];
    		a_plus_long = (a_plus_long<<1) | a_plus;
    		int a_minus = c_minus[i];
    		a_minus_long = (a_minus_long<<1) | a_minus;
    		currBitIndex++;
		}
    	if (currBitIndex!=0) {
    		while (currBitIndex!=MainConst.EVAL_BIT_LENGTH) {
        		a_plus_long = (a_plus_long<<1);
        		a_minus_long = (a_minus_long<<1);
        		currBitIndex++;	
    		}
    		binPlus[currLongIndex] = a_plus_long;
			binMinus[currLongIndex] = a_minus_long;
    	}
    }
}
